package Data_base;
import java.sql.*;
import java.util.Scanner;
//增加
public class Zengjia {
    public void zengjia() throws Exception
    {
        try
        {
            DB ty=new DB();
            Class.forName(ty.Driver_class);
            Connection con= DriverManager.getConnection(ty.Database_url,ty.Database_user,ty.Database_password);
            Statement stmt=null;//发送数据库语句到数据库执行
            Scanner sc = new Scanner(System.in);
            System.out.print("请输入新增id:");
            String mm = sc.nextLine();
            System.out.print("请输入新增用户名:");
            String zh = sc.nextLine();
            System.out.print("请输入新增密码:");
            String mt = sc.nextLine();
            System.out.print("请输入新增邮件:");
            String ma = sc.nextLine();
            if(mm.equals("id"))
            {
                System.out.println("用户id不能重复");
            }
            else {
                stmt=con.createStatement();
                stmt.executeUpdate("insert into users(id,name,password,email) values("+mm+",'"+zh+"','"+mt+"','"+ma+"')");
                System.out.println("新增用户成功");

                con.close();
           }

           // ResultSet huoqu=fasong.executeQuery(sql);
           // System.out.println();

        }catch(Exception e)
        {e.printStackTrace(); }

    }
}
